<?php
/********************************************
 *
 *
 *
 *
 *
 ********************************************/


ob_start('ob_gzhandler');
ob_implicit_flush(0);

header('content-type: text/html; charset=utf-8');

!defined('TIMEZONE')	&& define('TIMEZONE', 'Asia/Shanghai');			// 优先进行时区设置
date_default_timezone_set(TIMEZONE);

!defined('DS')		&& define('DS', DIRECTORY_SEPARATOR);				// 路径连接符
!defined('PS')		&& define('PS', PATH_SEPARATOR);					// PATH 连接符
!defined('NOW')		&& define('NOW', time());							// 当前时间
!defined('TODAY')		&& define('TODAY', mktime(0,0,0));				// 今天的起始时间
!defined('UJN_PATH')	&& define('UJN_PATH', dirname(__FILE__) . DS);	// UJN 根目录路径
!defined('THIRD_PATH')	&& define('THIRD_PATH', dirname(__FILE__) . DS . 'thridlibs' . DS);	// UJN 根目录路径

function __autoload($classname) {
	if(class_exists('ujn', false)) ujn::loadClass($classname);
}

function logged($log_txt, $flag = 'logged', $ex_file_flag = 'H', $ex_path_flag = 'Y/md/', $ex_path_perm = 0777) {
	$ex_path = ujn::getCFG('tmp_path') . '/' . $flag . '/' . date($ex_path_flag);
	if(!is_dir($ex_path)) mkdir($ex_path, $ex_path_perm, true);

	$ex_file = $ex_path . date($ex_file_flag) . '.log'; // 默認每小时1个记录
	file_put_contents($ex_file, $log_txt . "\n", FILE_APPEND);
}

function exception_handler(Exception $ex) {

	$msg	= $ex->getMessage();
	$trace	= $ex->getTraceAsString();
	$file	= $ex->getFile();
	$line	= $ex->getLine();
	$code	= $ex->getCode();
	$req	= var_export($_REQUEST, true);

	$log_txt = date('Y-m-d H:i:s') . <<<EOT
==========================
MSG: --->
[ $msg ]

FILE: --->
[ $file ] in line [ $line ]

CODE: --->
{
$code
}

REQUEST --->
$req

TRACE: --->
$trace
==========  OVER  ========

EOT;

	logged($log_txt, 'exception');

	echo $msg;
	exit;
}
set_exception_handler('exception_handler');

//function error_handler() {
//	return t
//}
//set_error_handler('error_handler');

include_once UJN_PATH . 'classes/core.php';

!defined('UJNLOADED') && define('UJNLOADED', true);